package org.abbett.eskine.dao.inmemory;

import java.io.StringWriter;

import net.java.textilej.parser.MarkupParser;
import net.java.textilej.parser.builder.HtmlDocumentBuilder;
import net.java.textilej.parser.markup.textile.TextileDialect;

import org.abbett.eskine.entity.Page;

/**
 * 
                A wiki page.
            
 */
public class InMemoryPage implements Page {


    /** Page ID */
    private String id;

    /** 
     * Get Page ID.
     *  
     * @return the id
     */
    public String getId() {
       return this.id;
    }

    /**
     * Set Page ID
     *
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }



    /** 
						Identifier of the user who owns this page.
					 */
    private String userId;

    /** 
     * Get User ID.
     *  
     * @return the userId
     */
    public String getUserId() {
       return this.userId;
    }

    /**
     * Set User ID
     *
     * @param userId
     */
    public void setUserId(String userId) {
        this.userId = userId;
    }



    /** Title */
    private String title;

    /** 
     * Get Title.
     *  
     * @return the title
     */
    public String getTitle() {
       return this.title;
    }

    /**
     * Set Title
     *
     * @param title
     */
    public void setTitle(String title) {
        this.title = title;
    }



    /** 
						User-entered content, in Textile format.
					 */
    private String content;

    /** 
     * Get Content.
     *  
     * @return the content
     */
    public String getContent() {
       return this.content;
    }

    /**
     * Set Content
     *
     * @param content
     */
    public void setContent(String content) {
        this.content = content;
    }



    /** 
						The content converted into HTML.
					 */
    private String htmlContent;

    /** 
     * Get HTML Content.
     *  
     * @return the htmlContent
     */
    public String getHtmlContent() {
       
    	StringWriter writer = new StringWriter();

    	HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer);
    	// avoid the <html> and <body> tags 
    	builder.setEmitAsDocument(false);

    	MarkupParser parser = new MarkupParser(new TextileDialect());
    	parser.setBuilder(builder);

    	parser.parse(getContent());
    	
    	return writer.toString();
    	
    }

    /**
     * Set HTML Content
     *
     * @param htmlContent
     */
    public void setHtmlContent(String htmlContent) {
        throw new RuntimeException("Cannot set HtmlContent. It is computed from content.");
    }



    /** Date Created */
    private java.util.Date dateCreated;

    /** 
     * Get Date Created.
     *  
     * @return the dateCreated
     */
    public java.util.Date getDateCreated() {
       return this.dateCreated;
    }

    /**
     * Set Date Created
     *
     * @param dateCreated
     */
    public void setDateCreated(java.util.Date dateCreated) {
        this.dateCreated = dateCreated;
    }



    /** Date Last Modified */
    private java.util.Date dateLastModified;

    /** 
     * Get Date Last Modified.
     *  
     * @return the dateLastModified
     */
    public java.util.Date getDateLastModified() {
       return this.dateLastModified;
    }

    /**
     * Set Date Last Modified
     *
     * @param dateLastModified
     */
    public void setDateLastModified(java.util.Date dateLastModified) {
        this.dateLastModified = dateLastModified;
    }


    public Object primaryKey() {
        return getId();
    }
}// clickframes::version=180187804::clickframes